<?php
/**
---------------------------------------
Table cate_du_an
---------------------------------------
*/

/**
count rows table cate_du_an
*/
function getRowsTypeDuAn() {
	$con = new ConnectDB();
	
	$sql = "Select COUNT(*) FROM cate_du_an WHERE del_flg='0'";
	return $con -> getvalueString($sql);
}

/**
get table cate_du_an limit
*/
function getTypeDuAnsLimit($start, $lenght) {
	$con = new ConnectDB();
	$sql = "Select cat_code, cat_name, date_create, date_update, isuse FROM cate_du_an WHERE del_flg='0' ORDER BY date_update DESC LIMIT ".$start.",".$lenght;
	return $con -> getvalueString($sql);
}

/**
get table cate_du_an
*/
function getTypeDuAns() {
	$con = new ConnectDB();
	$tbl = "cate_du_an";
	$fn = array('cat_code', 'cat_name', 'date_create', 'date_update');
	$condetion = array('isuse' => '1', 'del_flg' => '0');
	return $con -> getvalue($tbl, $fn, $condetion);
}

/**
get table cate_du_an by id
*/
function getTypeDuAnByID($id) {
	$con = new ConnectDB();
	$tbl = "cate_du_an";
	$fn = array('cat_code', 'cat_name', 'date_create', 'date_update', 'isuse');
	$condetion = array('cat_code' => $id, 'del_flg' => '0');
	return $con -> getvalue($tbl, $fn, $condetion);
}

/**
insert table cate_du_an
*/
function insertTypeDuAn($id, $name) {
	$con = new ConnectDB();
	$tbl = "cate_du_an";
	$fn = array('cat_code' => $id, 'cat_name' => $name, 'date_create' => time(), 'date_update' => time());
	return $con -> insert($tbl, $fn);
}

/**
display table cate_du_an for id
*/
function displayTypeDuAn($id, $isuse) {
	$con = new ConnectDB();
	$tbl = "cate_du_an";
	$fn = array('isuse' => $isuse);
	$conf = array('cat_code' => $id);
	return $con -> update($tbl, $fn, $conf);
}
/**
update display list id
*/
function displayTypeDuAnList($ids, $isuse) {
	$con = new ConnectDB();
	$tbl = "cate_du_an";
	$fn = array('isuse' => $isuse);
	$rowid = 'cat_code';
	return $con -> updatedels($tbl, $fn, $rowid, $ids);
}

/**
delete table cate_du_an for list id
*/
function deleteListTypeDuAn($ids) {
	$con = new ConnectDB();
	$tbl = "cate_du_an";
	$fn = array('del_flg' => '1');
	$rowid = 'cat_code';
	return $con -> updatedels($tbl, $fn, $rowid, $ids);
}

/**
delete table cate_du_an for id
*/
function deleteTypeDuAn($id) {
	$con = new ConnectDB();
	$tbl = "cate_du_an";
	$fn = array('del_flg' => '1');
	$conf = array('cat_code' => $id);
	return $con -> update($tbl, $fn, $conf);
}

/**
update Product
*/
function updateTypeDuAn($id, $name) {
	$con = new ConnectDB();
	$tbl = "cate_du_an";
	$fn = array('cat_name' => $name, 'date_update' => time());
	$conf = array('cat_code' => $id);
	return $con -> update($tbl, $fn, $conf);
}


/**
---------------------------------------
Table du_an_tc
---------------------------------------
*/

/**
count rows table du_an_tc
*/
function getRowsDuAn($type) {
	$con = new ConnectDB();
	
	$sql = "Select COUNT(*) FROM du_an_tc as d, cate_du_an as c WHERE c.cat_code = d.cat_code ";
	if($type != "") {
		$sql .= "AND d.cat_code='".$type."' ";
	}
	$sql .= "AND d.del_flg='0' AND c.del_flg='0' AND c.isuse='1'";
	return $con -> getvalueString($sql);
}

/**
get table du_an_tc limit
*/
function getDuAnsLimit($type, $start, $lenght) {
	$con = new ConnectDB();
	$sql = "Select d.pro_code, d.cat_code, c.cat_name, d.title, d.link, d.name_du_an, d.chu_dau_tu, d.address, d.dien_tich, d.thiet_ke_thi_cong, d.content_tt, d.tac_gia, d.date_create, d.date_update, d.isuse FROM du_an_tc as d, cate_du_an as c WHERE c.cat_code = d.cat_code ";
	if($type != "") {
		$sql .= "AND d.cat_code='".$type."' ";
	}
	$sql .= "AND d.del_flg='0' AND c.del_flg='0' AND c.isuse='1' ORDER BY d.date_update DESC LIMIT ".$start.",".$lenght;
	return $con -> getvalueString($sql);
}

/**
get table du_an_tc
*/
function getDuAns($type) {
	$con = new ConnectDB();
	$sql = "Select d.pro_code, d.cat_code, c.cat_name, d.title, d.link, d.name_du_an, d.chu_dau_tu, d.address, d.dien_tich, d.thiet_ke_thi_cong, d.content_tt, d.tac_gia, d.date_create, d.date_update, d.isuse WHERE FROM du_an_tc as d, cate_du_an as c WHERE c.cat_code = d.cat_code ";
	if($type != "") {
		$sql .= "AND d.cat_code='".$type."' ";
	}
	$sql .= "AND d.del_flg='0' AND c.del_flg='0' AND c.isuse='1' ORDER BY d.date_update DESC";
	return $con -> getvalueString($sql);
}

/**
get table du_an_tc by id
*/
function getDuAnByID($id) {
	$con = new ConnectDB();
	$sql = "Select d.pro_code, d.cat_code, c.cat_name, d.title, d.link, d.name_du_an, d.chu_dau_tu, d.address, d.dien_tich, d.thiet_ke_thi_cong, d.content_tt, d.content, d.tac_gia, d.date_create, d.date_update, d.isuse FROM du_an_tc as d, cate_du_an as c WHERE d.pro_code = '".$id."' AND c.cat_code = d.cat_code AND d.del_flg='0' AND c.del_flg='0' AND c.isuse='1'";
	return $con -> getvalueString($sql);
}

/**
insert table du_an_tc
*/
function insertDuAn($id, $type, $title, $link, $name_du_an, $chu_dau_tu, $address, $dien_tich, $thiet_ke_thi_cong, $content_tt, $content, $tac_gia) {
	$con = new ConnectDB();
	$tbl = "du_an_tc";
	$fn = array('pro_code' => $id, 'cat_code' => $type, 'title' => $title, 'link' => $link, 'name_du_an' => $name_du_an, 'chu_dau_tu' => $chu_dau_tu, 'address' => $address, 'dien_tich' => $dien_tich, 'thiet_ke_thi_cong' => $thiet_ke_thi_cong, 'content_tt' => $content_tt, 'content' => $content, 'tac_gia' => $tac_gia, 'date_create' => time(), 'date_update' => time());
	return $con -> insert($tbl, $fn);
}

/**
display table du_an_tc for id
*/
function displayDuAn($id, $isuse) {
	$con = new ConnectDB();
	$tbl = "du_an_tc";
	$fn = array('isuse' => $isuse);
	$conf = array('pro_code' => $id);
	return $con -> update($tbl, $fn, $conf);
}
/**
update display list id
*/
function displayDuAnList($ids, $isuse) {
	$con = new ConnectDB();
	$tbl = "du_an_tc";
	$fn = array('isuse' => $isuse);
	$rowid = 'pro_code';
	return $con -> updatedels($tbl, $fn, $rowid, $ids);
}

/**
delete table du_an_tc for list id
*/
function deleteListDuAn($ids) {
	$con = new ConnectDB();
	$tbl = "du_an_tc";
	$fn = array('del_flg' => '1');
	$rowid = 'pro_code';
	return $con -> updatedels($tbl, $fn, $rowid, $ids);
}

/**
delete table du_an_tc for id
*/
function deleteDuAn($id) {
	$con = new ConnectDB();
	$tbl = "du_an_tc";
	$fn = array('del_flg' => '1');
	$conf = array('pro_code' => $id);
	return $con -> update($tbl, $fn, $conf);
}

/**
update du_an_tc
*/
function updateDuAn($id, $type, $title, $link, $name_du_an, $chu_dau_tu, $address, $dien_tich, $thiet_ke_thi_cong, $content_tt, $content, $tac_gia) {
	$con = new ConnectDB();
	$tbl = "du_an_tc";
	$fn = array('cat_code' => $type, 'title' => $title, 'link' => $link, 'name_du_an' => $name_du_an, 'chu_dau_tu' => $chu_dau_tu, 'address' => $address, 'dien_tich' => $dien_tich, 'thiet_ke_thi_cong' => $thiet_ke_thi_cong, 'content_tt' => $content_tt, 'content' => $content, 'tac_gia' => $tac_gia, 'date_update' => time());
	$conf = array('pro_code' => $id);
	return $con -> update($tbl, $fn, $conf);
}


/**
INDEX
*/
function getRowsDuAnIndex($type) {
	$con = new ConnectDB();
	
	$sql = "Select COUNT(*) FROM du_an_tc as d, cate_du_an as c WHERE c.cat_code = d.cat_code ";
	if($type != "") {
		$sql .= "AND d.cat_code='".$type."' ";
	}
	$sql .= "AND d.del_flg='0' AND c.del_flg='0' AND c.isuse='1' AND d.isuse='1'";
	return $con -> getvalueString($sql);
}

/**
get table du_an_tc limit
*/
function getDuAnsLimitIndex($type, $start, $lenght) {
	$con = new ConnectDB();
	$sql = "Select d.pro_code, d.cat_code, c.cat_name, d.title, d.link, d.content_tt, d.tac_gia, d.date_create, d.date_update FROM du_an_tc as d, cate_du_an as c WHERE c.cat_code = d.cat_code ";
	if($type != "") {
		$sql .= "AND d.cat_code='".$type."' ";
	}
	$sql .= "AND d.del_flg='0' AND c.del_flg='0' AND c.isuse='1' AND d.isuse='1' ORDER BY d.date_update DESC LIMIT ".$start.",".$lenght;
	return $con -> getvalueString($sql);
}

/**
get products by id type product
*/
function getDuAnsLienQuan($idpro, $type) {
	$con = new ConnectDB();
	$sql = "Select d.pro_code, d.cat_code, c.cat_name, d.title, d.link, d.content_tt, d.tac_gia, d.date_create, d.date_update, d.isuse FROM du_an_tc as d, cate_du_an as c WHERE c.cat_code = d.cat_code AND d.cat_code='".$type."' AND d.pro_code<>'".$idpro."' AND d.del_flg='0' AND c.del_flg='0' AND c.isuse='1' AND d.isuse='1' ORDER BY d.date_update DESC LIMIT 0,6";
	return $con -> getvalueString($sql);
}
?>